import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProWeeklogVO, ProWeeklogForm, ProWeeklogQuery, ProWeeklogRecordForm, ProWeeklogRecordVO } from '@/api/project/log/weeklog/types';

/**
 * 查询周日志的主表列表
 * @param query
 * @returns {*}
 */

export const listProWeeklog = (query?: ProWeeklogQuery): AxiosPromise<ProWeeklogVO[]> => {
  return request({
    url: '/pro/weeklog/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询周日志的主表详细
 * @param id
 */
export const getProWeeklog = (id: string | number): AxiosPromise<ProWeeklogVO> => {
  return request({
    url: '/pro/weeklog/' + id,
    method: 'get'
  });
};

/**
 * 新增周日志的主表
 * @param data
 */
export const addProWeeklog = (data: ProWeeklogForm) => {
  return request({
    url: '/pro/weeklog',
    method: 'post',
    data: data
  });
};

/**
 * 修改周日志的主表
 * @param data
 */
export const updateProWeeklog = (data: ProWeeklogForm) => {
  return request({
    url: '/pro/weeklog',
    method: 'put',
    data: data
  });
};

/**
 * 删除周日志的主表
 * @param id
 */
export const delProWeeklog = (id: string | number | Array<string | number>) => {
  return request({
    url: '/pro/weeklog/' + id,
    method: 'delete'
  });
};

/**
 * 根据项目ID获取周日志数据（仅查询，不初始化）
 * @param proId 项目ID
 */
export const getWeeklogByProId = (proId: number): AxiosPromise<ProWeeklogVO> => {
  return request({
    url: `/pro/weeklog/list/${proId}`,
    method: 'get'
  });
};

/**
 * 初始化项目周日志
 * @param proId 项目ID
 */
export const initWeeklog = (proId: number, flag: boolean): AxiosPromise<number> => {
  return request({
    url: `/pro/weeklog/init/${proId}/${flag}`,
    method: 'post'
  });
};

/**
 * 更新周日志记录
 * @param data 周日志记录数据
 */
export const updateWeeklogRecord = (data: ProWeeklogRecordForm) => {
  return request({
    url: '/pro/weeklog/record',
    method: 'put',
    data: data
  });
};

/**
 * 获取节点编辑记录统计
 * @param id 周日志记录ID
 */
export const getWeeklogRecordStatistic = (id: string | number): AxiosPromise<ProWeeklogRecordVO[]> => {
  return request({
    url: `/pro/weeklog/statistic/${id}`,
    method: 'get'
  });
};

/**
 * 批量更新周日志记录
 * @param data 周日志记录数据列表
 */
export const batchUpdateWeeklogRecord = (data: ProWeeklogRecordForm[]) => {
  return request({
    url: '/pro/weeklog/record/batch',
    method: 'put',
    data: data
  });
};

/**
 * 分页查询周日志记录
 * @param query 查询参数
 */
export const listWeeklogRecord = (query?: any): AxiosPromise<ProWeeklogRecordVO[]> => {
  return request({
    url: '/pro/weeklog/record/list',
    method: 'get',
    params: query
  });
};

/**
 * 根据周日志ID查询周总结信息
 * @param weeklogId 周日志ID
 */
export const getWeeklogById = (weeklogId: string | number): AxiosPromise<ProWeeklogVO> => {
  return request({
    url: `/pro/weeklog/${weeklogId}`,
    method: 'get'
  });
};

/**
 * 查询周总结审核分页列表
 * @param query 查询参数
 */
export const listProWeeklogAudit = (query?: any): AxiosPromise<ProWeeklogVO[]> => {
  return request({
    url: '/pro/weeklog/auditList',
    method: 'get',
    params: query
  });
};